package com.tn.controller.key;

import java.util.List;
import java.util.Map;

import com.tn.controller.alarm.common.model.CommonVO;
import com.tn.dao.key.ShortcutKey;
import com.tn.dao.key.ShortcutKeyAttr;
import com.tn.dao.key.ShortcutKeyMapper;
import com.tn.service.key.ShortcutKeyService;
import com.tn.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 快捷键Controller
 * 
 * @author location
 * @date 2022-11-24
 */
@RestController
@RequestMapping("/aucy/key")
public class ShortcutKeyController
{
    @Autowired
    private ShortcutKeyService shortcutKeyService;


    /**
     * 获取快捷键详细信息
     */
    @GetMapping(value = "/info/{id}")
    public CommonVO<Object> getInfo(@PathVariable("id") Long id)
    {
        return new CommonVO<>(shortcutKeyService.selectShortcutKeyById(id));
    }

    /**
     * 新增快捷键
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST}, produces = "application/json")
    public CommonVO<Object> add(@RequestBody ShortcutKey shortcutKey)
    {
       shortcutKeyService.insertShortcutKey(shortcutKey);
        return new CommonVO<>();
    }


//    /**
//     * 新增快捷键
//     */
//    @RequestMapping(value = "/insert", method = {RequestMethod.POST}, produces = "application/json")
//    public CommonVO<Object> insert(@RequestBody ShortcutKey shortcutKey)
//    {   List<Map>list=mapper.selectShortList();
//        for (Map map : list) {
//            String value_code = map.get("value_code").toString();
//            ShortcutKey shortcutKey1 = JsonUtil.string2Obj(value_code, ShortcutKey.class);
//            shortcutKey1.setKeyCode(map.get("key_code").toString());
//            mapper.insert(shortcutKey1);
//        }
//        return new CommonVO<>();
//    }


    /**
     * 修改快捷键
     */
    @RequestMapping(value = "/edit", method = {RequestMethod.POST}, produces = "application/json")
    public CommonVO<Object> edit(@RequestBody ShortcutKey shortcutKey)
    {
       shortcutKeyService.updateShortcutKey(shortcutKey);
        return new CommonVO<>();
    }

    /**
     * 删除快捷键
     */
    @RequestMapping(value = "/delete", method = {RequestMethod.POST}, produces = "application/json")
    public CommonVO<Object> remove(@RequestBody List<Long> ids)
    {
        shortcutKeyService.deleteShortcutKeyByIds(ids);
        return new CommonVO<>();
    }
}
